package com.uzai.console.service.fd.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.uzai.common.dto.fadan.FollowQfConfig;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.common.enums.RedisCacheKeyEnum;
import com.uzai.common.exception.BusinessException;
import com.uzai.common.result.ResponseCode;
import com.uzai.common.utils.EsIndexName;
import com.uzai.console.common.utils.DateUtil;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.constant.ES.ElasticsearchUtilGroupMsg;
import com.uzai.console.dto.fd.fddeviceplangroup.FdDevicePlanGroupDto;
import com.uzai.console.dto.fd.fdfollowconfigqf.FdFollowConfigQfDto;
import com.uzai.console.dto.fd.fdfollowconfigqf.FdFollowConfigQfIdDto;
import com.uzai.console.dto.fd.fdfollowconfigqf.FdFollowConfigQfQuery;
import com.uzai.console.dto.fd.fdfollowconfigqf.FdFollowConfigQfStatusDto;
import com.uzai.console.dto.fd.fdfollowconfigqfgroup.FdFollowConfigQfGroupDto;
import com.uzai.console.dto.fd.fdfollowconfigqfkeyword.FdFollowConfigQfKeywordDto;
import com.uzai.console.dto.rocketmq.pyqfollow.FollowConfigDto;
import com.uzai.console.entity.*;
import com.uzai.console.entity.es.EsWorkWxGroupInfo;
import com.uzai.console.entity.es.EsWxContacts;
import com.uzai.console.mapper.*;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.fd.FdFollowConfigQfService;
import com.uzai.console.service.feign.UzaiImClientFeignService;
import com.uzai.console.service.merchant.MerchantService;
import com.uzai.console.vo.fd.fddeviceplan.FdDevicePlanVo;
import com.uzai.console.vo.fd.fddeviceplangroup.FdDevicePlanGroupVo;
import com.uzai.console.vo.fd.fddeviceplangroup.GroupSendDeviceInfoVo;
import com.uzai.console.vo.fd.fdfollowconfigqf.FdFollowConfigQfVo;
import com.uzai.console.vo.fd.fdfollowconfigqfgroup.FdFollowConfigQfGroupVo;
import com.uzai.console.vo.fd.fdfollowconfigqfgrouptuo.FdFollowConfigQfGroupTuoVo;
import com.uzai.console.vo.fd.fdfollowconfigqfkeyword.FdFollowConfigQfKeywordVo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 发单跟发配置
 * @author liuqi
 * @date 2021年08月13日 11:34
 */
@Service
public class FdFollowConfigQfServiceImpl implements FdFollowConfigQfService {

    Logger logger = LoggerFactory.getLogger(FdFollowConfigQfServiceImpl.class);

    @Autowired
    private FdFollowConfigQfMapper fdFollowConfigQfMapper;
    @Autowired
    private UzaiImClientFeignService uzaiImClientFeignService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private FdFollowConfigQfGroupMapper fdFollowConfigQfGroupMapper;
    @Autowired
    private FdFollowConfigQfGroupTuoMapper fdFollowConfigQfGroupTuoMapper;
    @Autowired
    private FdFollowConfigQfKeywordMapper fdFollowConfigQfKeywordMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private MerchantService merchantService;
    @Autowired
    private ElasticsearchUtilGroupMsg elasticsearchUtilGroupMsg;

    /**
     * 查询发单跟发配置列表
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param fdFollowConfigQfQuery
     * @return null
     */
    public Page<FdFollowConfigQfVo> findFdFollowConfigQfList(FdFollowConfigQfQuery fdFollowConfigQfQuery){
        //新建返回到页面的LIST对象
        List<FdFollowConfigQfVo> fdFollowConfigQfPageVoList = new ArrayList<>();

        //执行分页查询对象
        Page<FdFollowConfigQf> page = new Page<>();
        fdFollowConfigQfQuery.convert(page);
        ArrayList<FdFollowConfigQf> fdFollowConfigQfList =  fdFollowConfigQfMapper.findByList(page, fdFollowConfigQfQuery);
        if(fdFollowConfigQfList != null && fdFollowConfigQfList.size() > 0){
            for (FdFollowConfigQf fdFollowConfigQf : fdFollowConfigQfList){
                FdFollowConfigQfVo fdFollowConfigQfPageVo = new FdFollowConfigQfVo();
                BeanUtils.copyProperties(fdFollowConfigQf, fdFollowConfigQfPageVo);
                fdFollowConfigQfPageVoList.add(fdFollowConfigQfPageVo);

                //获取群信息
                List<FdFollowConfigQfGroup> fdFollowConfigQfGroupList = fdFollowConfigQfGroupMapper.findByListByFdFollowConfigQfId(fdFollowConfigQf.getId(), fdFollowConfigQf.getMerId());
                if(fdFollowConfigQfGroupList != null && fdFollowConfigQfGroupList.size() > 0){
                    //封装群信息列表
                    List<FdFollowConfigQfGroupVo> fdFollowConfigQfGroupVoList = new ArrayList<>();
                    fdFollowConfigQfPageVo.setFdFollowConfigQfGroupVoList(fdFollowConfigQfGroupVoList);

                    for (FdFollowConfigQfGroup fdFollowConfigQfGroup : fdFollowConfigQfGroupList) {
                        FdFollowConfigQfGroupVo fdFollowConfigQfGroupVo = new FdFollowConfigQfGroupVo();
                        BeanUtils.copyProperties(fdFollowConfigQfGroup, fdFollowConfigQfGroupVo);
                        //封装群信息
                        fdFollowConfigQfGroupVoList.add(fdFollowConfigQfGroupVo);

                        //托机器人信息列表
                        List<FdFollowConfigQfGroupTuo> fdFollowConfigQfGroupTuoList = fdFollowConfigQfGroupTuoMapper.findByListByFdFollowConfigQfGroupId(fdFollowConfigQfGroup.getId(), fdFollowConfigQfGroup.getMerId());
                            if(fdFollowConfigQfGroupTuoList != null && fdFollowConfigQfGroupTuoList.size() > 0){
                                List<FdFollowConfigQfGroupTuoVo> fdFollowConfigQfGroupTuoVoList = new ArrayList<>();
                                for (FdFollowConfigQfGroupTuo fdFollowConfigQfGroupTuo : fdFollowConfigQfGroupTuoList) {
                                    FdFollowConfigQfGroupTuoVo fdFollowConfigQfGroupTuoVo = new FdFollowConfigQfGroupTuoVo();
                                    fdFollowConfigQfGroupTuoVo.setDeviceUniqueId(fdFollowConfigQfGroupTuo.getTuoDeviceUniqueId());
                                    //托机器人信息
                                    Device device = deviceService.findDeviceInfoByDeviceUniqueId(fdFollowConfigQfGroupTuo.getTuoDeviceUniqueId(), fdFollowConfigQfGroup.getDeviceType(), fdFollowConfigQfGroup.getMerId());
                                    if(device != null){
                                        BeanUtils.copyProperties(device, fdFollowConfigQfGroupTuoVo);
                                    }
                                    fdFollowConfigQfGroupTuoVoList.add(fdFollowConfigQfGroupTuoVo);
                                }
                                fdFollowConfigQfGroupVo.setFdFollowConfigQfGroupTuoVoList(fdFollowConfigQfGroupTuoVoList);
                            }

                    }
                }

                //气氛组常用语设置
                List<FdFollowConfigQfKeyword> fdFollowConfigQfKeywordList = fdFollowConfigQfKeywordMapper.findByListByFdFollowConfigQfId(fdFollowConfigQf.getId(), fdFollowConfigQf.getMerId());
                if(fdFollowConfigQfKeywordList != null && fdFollowConfigQfKeywordList.size() > 0){
                    List<FdFollowConfigQfKeywordVo> fdFollowConfigQfKeywordVoList = new ArrayList<>();
                    fdFollowConfigQfPageVo.setFdFollowConfigQfKeywordVoList(fdFollowConfigQfKeywordVoList);
                    for (FdFollowConfigQfKeyword fdFollowConfigQfKeyword : fdFollowConfigQfKeywordList) {
                        FdFollowConfigQfKeywordVo fdFollowConfigQfKeywordVo = new FdFollowConfigQfKeywordVo();
                        BeanUtils.copyProperties(fdFollowConfigQfKeyword, fdFollowConfigQfKeywordVo);
                        fdFollowConfigQfKeywordVoList.add(fdFollowConfigQfKeywordVo);
                        try {
                            if(StringUtils.isNotBlank(fdFollowConfigQfKeyword.getReplyInfo())){
                                List<FdFollowConfigQfKeywordVo.ReplyInfo> replyInfoList = JSONObject.parseArray(fdFollowConfigQfKeyword.getReplyInfo(), FdFollowConfigQfKeywordVo.ReplyInfo.class);
                                fdFollowConfigQfKeywordVo.setReplyInfoList(replyInfoList);
                            }
                        }catch (Exception e){

                        }

                    }
                }
            }
        }

        //返回到页面分页对象
        Page<FdFollowConfigQfVo> pageVo = new Page<>();
        BeanUtils.copyProperties(page, pageVo);
        pageVo.setRecords(fdFollowConfigQfPageVoList);
        //将分页信息复制到返回到页面的分页MO当中
        return pageVo;
    }

    /**
     * 查询发单跟发配置详情
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param fdFollowConfigQfIdDto
     * @return null
     */
    public FdFollowConfigQfVo findFdFollowConfigQf(FdFollowConfigQfIdDto fdFollowConfigQfIdDto){
        if(fdFollowConfigQfIdDto.getId() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        FdFollowConfigQf fdFollowConfigQf = fdFollowConfigQfMapper.selectById(fdFollowConfigQfIdDto.getId(), fdFollowConfigQfIdDto.getMerId());

        if(fdFollowConfigQf == null ){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该发单跟发配置不存在");
        }

        FdFollowConfigQfVo fdFollowConfigQfVo = new FdFollowConfigQfVo();
        BeanUtils.copyProperties(fdFollowConfigQf, fdFollowConfigQfVo);

        //获取群信息
        List<FdFollowConfigQfGroup> fdFollowConfigQfGroupList = fdFollowConfigQfGroupMapper.findByListByFdFollowConfigQfId(fdFollowConfigQf.getId(), fdFollowConfigQf.getMerId());
        if(fdFollowConfigQfGroupList != null && fdFollowConfigQfGroupList.size() > 0){
            //封装群信息列表
            List<FdFollowConfigQfGroupVo> fdFollowConfigQfGroupVoList = new ArrayList<>();
            fdFollowConfigQfVo.setFdFollowConfigQfGroupVoList(fdFollowConfigQfGroupVoList);

            for (FdFollowConfigQfGroup fdFollowConfigQfGroup : fdFollowConfigQfGroupList) {
                FdFollowConfigQfGroupVo fdFollowConfigQfGroupVo = new FdFollowConfigQfGroupVo();
                BeanUtils.copyProperties(fdFollowConfigQfGroup, fdFollowConfigQfGroupVo);
                //封装群信息
                fdFollowConfigQfGroupVoList.add(fdFollowConfigQfGroupVo);

                //托机器人信息列表
                List<FdFollowConfigQfGroupTuo> fdFollowConfigQfGroupTuoList = fdFollowConfigQfGroupTuoMapper.findByListByFdFollowConfigQfGroupId(fdFollowConfigQfGroup.getId(), fdFollowConfigQfGroup.getMerId());
                if(fdFollowConfigQfGroupTuoList != null && fdFollowConfigQfGroupTuoList.size() > 0){
                    List<FdFollowConfigQfGroupTuoVo> fdFollowConfigQfGroupTuoVoList = new ArrayList<>();
                    for (FdFollowConfigQfGroupTuo fdFollowConfigQfGroupTuo : fdFollowConfigQfGroupTuoList) {
                        FdFollowConfigQfGroupTuoVo fdFollowConfigQfGroupTuoVo = new FdFollowConfigQfGroupTuoVo();
                        fdFollowConfigQfGroupTuoVo.setDeviceUniqueId(fdFollowConfigQfGroupTuo.getTuoDeviceUniqueId());
                        //托机器人信息
                        Device device = deviceService.findDeviceInfoByDeviceUniqueId(fdFollowConfigQfGroupTuo.getTuoDeviceUniqueId(), fdFollowConfigQfGroup.getDeviceType(), fdFollowConfigQfGroup.getMerId());
                        if(device != null){
                            BeanUtils.copyProperties(device, fdFollowConfigQfGroupTuoVo);
                        }
                        fdFollowConfigQfGroupTuoVoList.add(fdFollowConfigQfGroupTuoVo);
                    }
                    fdFollowConfigQfGroupVo.setFdFollowConfigQfGroupTuoVoList(fdFollowConfigQfGroupTuoVoList);
                }

            }
        }

        //气氛组常用语设置
        List<FdFollowConfigQfKeyword> fdFollowConfigQfKeywordList = fdFollowConfigQfKeywordMapper.findByListByFdFollowConfigQfId(fdFollowConfigQf.getId(), fdFollowConfigQf.getMerId());
        if(fdFollowConfigQfKeywordList != null && fdFollowConfigQfKeywordList.size() > 0){
            List<FdFollowConfigQfKeywordVo> fdFollowConfigQfKeywordVoList = new ArrayList<>();
            fdFollowConfigQfVo.setFdFollowConfigQfKeywordVoList(fdFollowConfigQfKeywordVoList);
            for (FdFollowConfigQfKeyword fdFollowConfigQfKeyword : fdFollowConfigQfKeywordList) {
                FdFollowConfigQfKeywordVo fdFollowConfigQfKeywordVo = new FdFollowConfigQfKeywordVo();
                BeanUtils.copyProperties(fdFollowConfigQfKeyword, fdFollowConfigQfKeywordVo);
                fdFollowConfigQfKeywordVoList.add(fdFollowConfigQfKeywordVo);
                try {
                    if(StringUtils.isNotBlank(fdFollowConfigQfKeyword.getReplyInfo())){
                        List<FdFollowConfigQfKeywordVo.ReplyInfo> replyInfoList = JSONObject.parseArray(fdFollowConfigQfKeyword.getReplyInfo(), FdFollowConfigQfKeywordVo.ReplyInfo.class);
                        fdFollowConfigQfKeywordVo.setReplyInfoList(replyInfoList);
                    }
                }catch (Exception e){

                }
            }
        }
        return fdFollowConfigQfVo;
    }

    /**
     * 添加发单跟发配置
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param fdFollowConfigQfDto
     * @return null
     */
    @Transactional
    public void addFdFollowConfigQf(FdFollowConfigQfDto fdFollowConfigQfDto){

        Long merId = fdFollowConfigQfDto.getMerId();

        if(StringUtils.isBlank(fdFollowConfigQfDto.getName())){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入任务名称");
        }

        if(fdFollowConfigQfDto.getGapMin() == null || fdFollowConfigQfDto.getGapMax() == null){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入延迟时间");
        }

        //关键词
        List<FdFollowConfigQfKeywordDto> fdFollowConfigQfKeywordDtoList = fdFollowConfigQfDto.getFdFollowConfigQfKeywordDtoList();
        if(fdFollowConfigQfKeywordDtoList == null || fdFollowConfigQfKeywordDtoList.size() == 0){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入智能回复信息");
        }

        //群信息
        List<FdFollowConfigQfGroupDto> fdFollowConfigQfGroupDtoList = fdFollowConfigQfDto.getFdFollowConfigQfGroupDtoList();
        if(fdFollowConfigQfGroupDtoList == null || fdFollowConfigQfGroupDtoList.size() == 0){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请添加群信息");
        }

        for (FdFollowConfigQfGroupDto fdFollowConfigQfGroupDto : fdFollowConfigQfGroupDtoList) {
            if(StringUtils.isBlank(fdFollowConfigQfGroupDto.getGroupId())){
                throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入群id");
            }

            if(StringUtils.isBlank(fdFollowConfigQfGroupDto.getDeviceType())){
                throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入设备类型");
            }

            if(fdFollowConfigQfGroupDto.getGroupUserWxid() == null){
                throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入被监控成员id");
            }

            if(fdFollowConfigQfGroupDto.getTuoDeviceInfoList() == null || fdFollowConfigQfGroupDto.getTuoDeviceInfoList().size() == 0){
                throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请选择气氛组机器人");
            }
        }

        //先添加跟发任务
        Integer now = DateUtil.getNowTime();
        FdFollowConfigQf fdFollowConfigQf = new FdFollowConfigQf();
        fdFollowConfigQf.setId(IdWorker.getId());
        fdFollowConfigQf.setMerId(merId);
        fdFollowConfigQf.setStatus(0); //默认关闭
        fdFollowConfigQf.setName(fdFollowConfigQfDto.getName());
        fdFollowConfigQf.setGapMin(fdFollowConfigQfDto.getGapMin());
        fdFollowConfigQf.setGapMax(fdFollowConfigQfDto.getGapMax());
        fdFollowConfigQf.setCreateTime(now);
        fdFollowConfigQf.setUpdateTime(now);
        fdFollowConfigQfMapper.insertSelective(fdFollowConfigQf);

        //保存群发设备方案群信息
        for (FdFollowConfigQfGroupDto fdFollowConfigQfGroupDto : fdFollowConfigQfGroupDtoList) {
            FdFollowConfigQfGroup fdFollowConfigQfGroup = new FdFollowConfigQfGroup();
            fdFollowConfigQfGroup.setId(IdWorker.getId());
            fdFollowConfigQfGroup.setMerId(merId);
            fdFollowConfigQfGroup.setFdFollowConfigQfId(fdFollowConfigQf.getId());
            fdFollowConfigQfGroup.setDeviceType(fdFollowConfigQfGroupDto.getDeviceType());
            fdFollowConfigQfGroup.setGroupId(fdFollowConfigQfGroupDto.getGroupId());
            fdFollowConfigQfGroup.setGroupUserWxid(fdFollowConfigQfGroupDto.getGroupUserWxid());
            fdFollowConfigQfGroup.setGroupUserName(fdFollowConfigQfGroupDto.getGroupUserName());
            //判断群存不存在
            //个人微信群
            if(fdFollowConfigQfGroupDto.getDeviceType().equals(DeviceTypeEnum.DT_PC_WECHAT.getKey())){
                //查询微信群
                String uzai_wx_contacts = EsIndexName.UZAI_WX_CONTACTS;
                uzai_wx_contacts = merchantService.getMechantOtherEsIndexName(uzai_wx_contacts, merId);
                //群主键merId_deviceId_wxid
                Map<String,Object> dataMp = elasticsearchUtilGroupMsg.searchDataById(uzai_wx_contacts, fdFollowConfigQfGroupDto.getGroupId(), null);
                EsWxContacts esWxContacts  = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(dataMp)), EsWxContacts.class);
                if(esWxContacts == null){
                    throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "此个人微信群不存在");
                }
                fdFollowConfigQfGroup.setDeviceUniqueId(esWxContacts.getDeviceUniqueId());
                fdFollowConfigQfGroup.setDeviceId(esWxContacts.getDeviceId());
                fdFollowConfigQfGroup.setGroupWxid(esWxContacts.getWxid());
                fdFollowConfigQfGroup.setGroupNick(esWxContacts.getNick());
            }else{
                //查询微信群
                String uzai_workwx_group_info = EsIndexName.UZAI_WORKWX_GROUP_INFO;
                uzai_workwx_group_info = merchantService.getMechantOtherEsIndexName(uzai_workwx_group_info, merId);
                //群主键merId_deviceId_wxid
                Map<String,Object> dataMp = elasticsearchUtilGroupMsg.searchDataById(uzai_workwx_group_info, fdFollowConfigQfGroupDto.getGroupId(), null);
                EsWorkWxGroupInfo esWorkWxGroupInfo  = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(dataMp)), EsWorkWxGroupInfo.class);
                if(esWorkWxGroupInfo == null){
                    throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "此企业微信群不存在");
                }
                fdFollowConfigQfGroup.setDeviceUniqueId(esWorkWxGroupInfo.getDeviceUniqueId());
                fdFollowConfigQfGroup.setDeviceId(esWorkWxGroupInfo.getDeviceId());
                fdFollowConfigQfGroup.setGroupWxid(esWorkWxGroupInfo.getGroupId());
                fdFollowConfigQfGroup.setGroupNick(esWorkWxGroupInfo.getNickName());
            }

            fdFollowConfigQfGroup.setCreateTime(now);
            fdFollowConfigQfGroup.setUpdateTime(now);
            fdFollowConfigQfGroupMapper.insertSelective(fdFollowConfigQfGroup);

            //保存托机器人信息
            if(fdFollowConfigQfGroupDto.getTuoDeviceInfoList() != null && fdFollowConfigQfGroupDto.getTuoDeviceInfoList().size() > 0){
                for (FdFollowConfigQfGroupDto.TuoDeviceInfo tuoDeviceInfo : fdFollowConfigQfGroupDto.getTuoDeviceInfoList()) {
                    Device device = deviceService.findDeviceInfoByDeviceUniqueId(tuoDeviceInfo.getDeviceUniqueId(), fdFollowConfigQfGroup.getDeviceType(), merId);
                    if(device == null){
                        throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "选择的气氛组机器人不存在");
                    }

                    FdFollowConfigQfGroupTuo fdFollowConfigQfGroupTuo = fdFollowConfigQfGroupTuoMapper.selectByUniqueIndex(merId, fdFollowConfigQfGroup.getGroupWxid(), fdFollowConfigQfGroup.getGroupUserWxid(), device.getDeviceId());
                    if(fdFollowConfigQfGroupTuo != null){
                        throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "气氛组机器人已经配置过了，不能重复配置。机器人wxid为："+ device.getDeviceId());
                    }

                    fdFollowConfigQfGroupTuo = new FdFollowConfigQfGroupTuo();
                    fdFollowConfigQfGroupTuo.setId(IdWorker.getId());
                    fdFollowConfigQfGroupTuo.setMerId(merId);
                    fdFollowConfigQfGroupTuo.setFdFollowConfigQfId(fdFollowConfigQf.getId());
                    fdFollowConfigQfGroupTuo.setFdFollowConfigQfGroupId(fdFollowConfigQfGroup.getId());
                    fdFollowConfigQfGroupTuo.setGroupId(fdFollowConfigQfGroupDto.getGroupId());
                    fdFollowConfigQfGroupTuo.setGroupWxid(fdFollowConfigQfGroup.getGroupWxid());
                    fdFollowConfigQfGroupTuo.setGroupUserWxid(fdFollowConfigQfGroup.getGroupUserWxid());
                    fdFollowConfigQfGroupTuo.setTuoDeviceUniqueId(tuoDeviceInfo.getDeviceUniqueId());
                    fdFollowConfigQfGroupTuo.setTuoDeviceId(device.getDeviceId());
                    fdFollowConfigQfGroupTuo.setCreateTime(now);
                    fdFollowConfigQfGroupTuo.setUpdateTime(now);
                    fdFollowConfigQfGroupTuoMapper.insertSelective(fdFollowConfigQfGroupTuo);
                }
            }
        }

        //保存气氛组跟发任务关键词
        for (FdFollowConfigQfKeywordDto fdFollowConfigQfKeywordDto : fdFollowConfigQfKeywordDtoList) {

            if(fdFollowConfigQfKeywordDto.getReplyInfoList() == null || fdFollowConfigQfKeywordDto.getReplyInfoList().size() ==0){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入关键词回复语");
            }

            //判断此Key是否重复
            FdFollowConfigQfKeyword fdFollowConfigQfKeyword = fdFollowConfigQfKeywordMapper.selectByUniqueIndex(fdFollowConfigQf.getMerId(), fdFollowConfigQf.getId(), fdFollowConfigQfKeywordDto.getKeyword());
            if(fdFollowConfigQfKeyword != null){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "关键词["+fdFollowConfigQfKeywordDto.getKeyword()+"]重复。");
            }

            fdFollowConfigQfKeyword = new FdFollowConfigQfKeyword();
            fdFollowConfigQfKeyword.setId(IdWorker.getId());
            fdFollowConfigQfKeyword.setMerId(merId);
            fdFollowConfigQfKeyword.setFdFollowConfigQfId(fdFollowConfigQf.getId());
            fdFollowConfigQfKeyword.setKeyword(fdFollowConfigQfKeywordDto.getKeyword());
            fdFollowConfigQfKeyword.setType(fdFollowConfigQfKeywordDto.getType());
            fdFollowConfigQfKeyword.setReplyInfo(JSONObject.toJSONString(fdFollowConfigQfKeywordDto.getReplyInfoList()));
            fdFollowConfigQfKeyword.setCreateTime(now);
            fdFollowConfigQfKeyword.setUpdateTime(now);
            fdFollowConfigQfKeywordMapper.insert(fdFollowConfigQfKeyword);
        }
    }

    /**
     * 修改气氛组跟发配置
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param fdFollowConfigQfDto
     * @return null
     */
    @Transactional
    public void updateFdFollowConfigQf(FdFollowConfigQfDto fdFollowConfigQfDto){

        Long merId = fdFollowConfigQfDto.getMerId();

        if(fdFollowConfigQfDto.getId() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        FdFollowConfigQf fdFollowConfigQf = fdFollowConfigQfMapper.selectById(fdFollowConfigQfDto.getId(), fdFollowConfigQfDto.getMerId());
        if(fdFollowConfigQf == null ){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该跟发配置不存在");
        }


        if(StringUtils.isBlank(fdFollowConfigQfDto.getName())){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入任务名称");
        }

        if(fdFollowConfigQfDto.getGapMin() == null || fdFollowConfigQfDto.getGapMax() == null){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入延迟时间");
        }

        //关键词
        List<FdFollowConfigQfKeywordDto> fdFollowConfigQfKeywordDtoList = fdFollowConfigQfDto.getFdFollowConfigQfKeywordDtoList();
        if(fdFollowConfigQfKeywordDtoList == null || fdFollowConfigQfKeywordDtoList.size() == 0){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入智能回复信息");
        }

        //群信息
        List<FdFollowConfigQfGroupDto> fdFollowConfigQfGroupDtoList = fdFollowConfigQfDto.getFdFollowConfigQfGroupDtoList();
        if(fdFollowConfigQfGroupDtoList == null || fdFollowConfigQfGroupDtoList.size() == 0){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请添加群信息");
        }

        for (FdFollowConfigQfGroupDto fdFollowConfigQfGroupDto : fdFollowConfigQfGroupDtoList) {
            if(StringUtils.isBlank(fdFollowConfigQfGroupDto.getGroupId())){
                throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入群id");
            }

            if(StringUtils.isBlank(fdFollowConfigQfGroupDto.getDeviceType())){
                throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入设备类型");
            }

            if(fdFollowConfigQfGroupDto.getGroupUserWxid() == null){
                throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请输入被监控成员id");
            }

            if(fdFollowConfigQfGroupDto.getTuoDeviceInfoList() == null || fdFollowConfigQfGroupDto.getTuoDeviceInfoList().size() == 0){
                throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请选择气氛组机器人");
            }
        }

        Integer now = DateUtil.getNowTime();
        fdFollowConfigQf.setName(fdFollowConfigQfDto.getName());
        fdFollowConfigQf.setGapMin(fdFollowConfigQfDto.getGapMin());
        fdFollowConfigQf.setGapMax(fdFollowConfigQfDto.getGapMax());
        fdFollowConfigQf.setUpdateTime(now);
        int i = fdFollowConfigQfMapper.updateById(fdFollowConfigQf);

        //查询旧气氛组机器人信息用于删除旧的缓存
        List<FdFollowConfigQfGroupTuo> fdFollowConfigQfGroupTuoList_old = fdFollowConfigQfGroupTuoMapper.findByListByFdFollowConfigQfId(fdFollowConfigQf.getId(), fdFollowConfigQfDto.getMerId());
        //新建新的气氛组机器人信息列表
        List<FdFollowConfigQfGroupTuo> fdFollowConfigQfGroupTuoList_new = new ArrayList<>();
        //批量删除该任务的关键词
        fdFollowConfigQfKeywordMapper.deleteByFdFollowConfigQfId(fdFollowConfigQfDto.getId(), fdFollowConfigQfDto.getMerId());
        //批量删除该任务群信息
        fdFollowConfigQfGroupMapper.deleteByFdFollowConfigQfId(fdFollowConfigQfDto.getId(), fdFollowConfigQfDto.getMerId());
        //批量删除该任务群托机器人信息
        fdFollowConfigQfGroupTuoMapper.deleteByFdFollowConfigQfId(fdFollowConfigQfDto.getId(), fdFollowConfigQfDto.getMerId());

        //保存气氛组跟发任务关键词
        for (FdFollowConfigQfKeywordDto fdFollowConfigQfKeywordDto : fdFollowConfigQfKeywordDtoList) {
            if(fdFollowConfigQfKeywordDto.getReplyInfoList() == null || fdFollowConfigQfKeywordDto.getReplyInfoList().size() ==0){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入关键词回复语");
            }

            //判断此Key是否重复
            FdFollowConfigQfKeyword fdFollowConfigQfKeyword = fdFollowConfigQfKeywordMapper.selectByUniqueIndex(fdFollowConfigQf.getMerId(), fdFollowConfigQf.getId(), fdFollowConfigQfKeywordDto.getKeyword());
            if(fdFollowConfigQfKeyword != null){
                throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "关键词["+fdFollowConfigQfKeywordDto.getKeyword()+"]重复。");
            }

            fdFollowConfigQfKeyword = new FdFollowConfigQfKeyword();
            fdFollowConfigQfKeyword.setId(IdWorker.getId());
            fdFollowConfigQfKeyword.setMerId(merId);
            fdFollowConfigQfKeyword.setFdFollowConfigQfId(fdFollowConfigQf.getId());
            fdFollowConfigQfKeyword.setKeyword(fdFollowConfigQfKeywordDto.getKeyword());
            fdFollowConfigQfKeyword.setType(fdFollowConfigQfKeywordDto.getType());
            fdFollowConfigQfKeyword.setReplyInfo(JSONObject.toJSONString(fdFollowConfigQfKeywordDto.getReplyInfoList()));
            fdFollowConfigQfKeyword.setCreateTime(now);
            fdFollowConfigQfKeyword.setUpdateTime(now);
            fdFollowConfigQfKeywordMapper.insert(fdFollowConfigQfKeyword);
        }

        //保存群发设备方案群信息
        for (FdFollowConfigQfGroupDto fdFollowConfigQfGroupDto : fdFollowConfigQfGroupDtoList) {
            FdFollowConfigQfGroup fdFollowConfigQfGroup = new FdFollowConfigQfGroup();
            fdFollowConfigQfGroup.setId(IdWorker.getId());
            fdFollowConfigQfGroup.setMerId(merId);
            fdFollowConfigQfGroup.setFdFollowConfigQfId(fdFollowConfigQf.getId());
            fdFollowConfigQfGroup.setDeviceType(fdFollowConfigQfGroupDto.getDeviceType());
            fdFollowConfigQfGroup.setGroupId(fdFollowConfigQfGroupDto.getGroupId());
            fdFollowConfigQfGroup.setGroupUserWxid(fdFollowConfigQfGroupDto.getGroupUserWxid());
            fdFollowConfigQfGroup.setGroupUserName(fdFollowConfigQfGroupDto.getGroupUserName());
            //判断群存不存在
            //个人微信群
            if(fdFollowConfigQfGroupDto.getDeviceType().equals(DeviceTypeEnum.DT_PC_WECHAT.getKey())){
                //查询微信群
                String uzai_wx_contacts = EsIndexName.UZAI_WX_CONTACTS;
                uzai_wx_contacts = merchantService.getMechantOtherEsIndexName(uzai_wx_contacts, merId);
                //群主键merId_deviceId_wxid
                Map<String,Object> dataMp = elasticsearchUtilGroupMsg.searchDataById(uzai_wx_contacts, fdFollowConfigQfGroupDto.getGroupId(), null);
                EsWxContacts esWxContacts  = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(dataMp)), EsWxContacts.class);
                if(esWxContacts == null){
                    throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "此个人微信群不存在");
                }
                fdFollowConfigQfGroup.setDeviceUniqueId(esWxContacts.getDeviceUniqueId());
                fdFollowConfigQfGroup.setDeviceId(esWxContacts.getDeviceId());
                fdFollowConfigQfGroup.setGroupWxid(esWxContacts.getWxid());
                fdFollowConfigQfGroup.setGroupNick(esWxContacts.getNick());
            }else{
                //查询微信群
                String uzai_workwx_group_info = EsIndexName.UZAI_WORKWX_GROUP_INFO;
                uzai_workwx_group_info = merchantService.getMechantOtherEsIndexName(uzai_workwx_group_info, merId);
                //群主键merId_deviceId_wxid
                Map<String,Object> dataMp = elasticsearchUtilGroupMsg.searchDataById(uzai_workwx_group_info, fdFollowConfigQfGroupDto.getGroupId(), null);
                EsWorkWxGroupInfo esWorkWxGroupInfo  = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(dataMp)), EsWorkWxGroupInfo.class);
                if(esWorkWxGroupInfo == null){
                    throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "此企业微信群不存在");
                }
                fdFollowConfigQfGroup.setDeviceUniqueId(esWorkWxGroupInfo.getDeviceUniqueId());
                fdFollowConfigQfGroup.setDeviceId(esWorkWxGroupInfo.getDeviceId());
                fdFollowConfigQfGroup.setGroupWxid(esWorkWxGroupInfo.getGroupId());
                fdFollowConfigQfGroup.setGroupNick(esWorkWxGroupInfo.getNickName());
            }

            fdFollowConfigQfGroup.setCreateTime(now);
            fdFollowConfigQfGroup.setUpdateTime(now);
            fdFollowConfigQfGroupMapper.insertSelective(fdFollowConfigQfGroup);

            //保存托机器人信息
            if(fdFollowConfigQfGroupDto.getTuoDeviceInfoList() != null && fdFollowConfigQfGroupDto.getTuoDeviceInfoList().size() > 0){
                for (FdFollowConfigQfGroupDto.TuoDeviceInfo tuoDeviceInfo : fdFollowConfigQfGroupDto.getTuoDeviceInfoList()) {
                    Device device = deviceService.findDeviceInfoByDeviceUniqueId(tuoDeviceInfo.getDeviceUniqueId(), fdFollowConfigQfGroup.getDeviceType(), merId);
                    if(device == null){
                        throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "选择的气氛组机器人不存在");
                    }

                    FdFollowConfigQfGroupTuo fdFollowConfigQfGroupTuo = fdFollowConfigQfGroupTuoMapper.selectByUniqueIndex(merId, fdFollowConfigQfGroup.getGroupWxid(), fdFollowConfigQfGroup.getGroupUserWxid(), device.getDeviceId());
                    if(fdFollowConfigQfGroupTuo != null){
                        throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "气氛组机器人已经配置过了，不能重复配置。机器人wxid为："+ device.getDeviceId());
                    }

                    fdFollowConfigQfGroupTuo = new FdFollowConfigQfGroupTuo();
                    fdFollowConfigQfGroupTuo.setId(IdWorker.getId());
                    fdFollowConfigQfGroupTuo.setMerId(merId);
                    fdFollowConfigQfGroupTuo.setFdFollowConfigQfId(fdFollowConfigQf.getId());
                    fdFollowConfigQfGroupTuo.setFdFollowConfigQfGroupId(fdFollowConfigQfGroup.getId());
                    fdFollowConfigQfGroupTuo.setGroupId(fdFollowConfigQfGroupDto.getGroupId());
                    fdFollowConfigQfGroupTuo.setGroupWxid(fdFollowConfigQfGroup.getGroupWxid());
                    fdFollowConfigQfGroupTuo.setGroupUserWxid(fdFollowConfigQfGroup.getGroupUserWxid());
                    fdFollowConfigQfGroupTuo.setTuoDeviceUniqueId(tuoDeviceInfo.getDeviceUniqueId());
                    fdFollowConfigQfGroupTuo.setTuoDeviceId(device.getDeviceId());
                    fdFollowConfigQfGroupTuo.setCreateTime(now);
                    fdFollowConfigQfGroupTuo.setUpdateTime(now);
                    fdFollowConfigQfGroupTuoMapper.insertSelective(fdFollowConfigQfGroupTuo);
                    fdFollowConfigQfGroupTuoList_new.add(fdFollowConfigQfGroupTuo);
                }
            }
        }

        //删除旧的机器人缓存
        if(fdFollowConfigQfGroupTuoList_old != null && fdFollowConfigQfGroupTuoList_old.size() > 0){
            for (FdFollowConfigQfGroupTuo fdFollowConfigQfGroupTuo_old : fdFollowConfigQfGroupTuoList_old) {
                String cacheKey_old = String.format(RedisCacheKeyEnum.FD_FOLLOW_QF_TASK_CACHE_KEY.getKey(), merId, fdFollowConfigQfGroupTuo_old.getTuoDeviceId(), fdFollowConfigQfGroupTuo_old.getGroupWxid(), fdFollowConfigQfGroupTuo_old.getGroupUserWxid());
                //先删除旧的缓存
                redisTemplate.delete(cacheKey_old);
            }
        }

        //新增加新机器人缓存
        if(fdFollowConfigQf.getStatus() == 1){ //如果任务为开启状态，则需要添加新的缓存
            //先封装关键词列表
            List<FollowQfConfig.KeyWordInfo> keyWordInfoList = new ArrayList<>();
            for (FdFollowConfigQfKeywordDto fdFollowConfigQfKeywordDto : fdFollowConfigQfKeywordDtoList) {
                FollowQfConfig.KeyWordInfo keyWordInfo = new FollowQfConfig.KeyWordInfo();
                keyWordInfo.setKeyword(fdFollowConfigQfKeywordDto.getKeyword());
                keyWordInfo.setType(fdFollowConfigQfKeywordDto.getType());
                keyWordInfoList.add(keyWordInfo);
            }

            //新增加气氛组缓存
            if(fdFollowConfigQfGroupTuoList_new != null && fdFollowConfigQfGroupTuoList_new.size() > 0) {
                for (FdFollowConfigQfGroupTuo fdFollowConfigQfGroupTuo_new : fdFollowConfigQfGroupTuoList_new) {
                    String cacheKey_new = String.format(RedisCacheKeyEnum.FD_FOLLOW_QF_TASK_CACHE_KEY.getKey(), merId, fdFollowConfigQfGroupTuo_new.getTuoDeviceId(), fdFollowConfigQfGroupTuo_new.getGroupWxid(), fdFollowConfigQfGroupTuo_new.getGroupUserWxid());
                    FollowQfConfig followQfConfig_redis = new FollowQfConfig();
                    followQfConfig_redis.setFdFollowConfigQfId(fdFollowConfigQf.getId());
                    followQfConfig_redis.setKeywords(keyWordInfoList);
                    //添加新的缓存
                    redisTemplate.opsForValue().set(cacheKey_new, JSONObject.toJSONString(followQfConfig_redis));

                }
            }
        }
    }

    /**
     * 删除
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param fdFollowConfigQfIdDto
     * @return null
     */
    @Transactional
    public void deleteFdFollowConfigQf(FdFollowConfigQfIdDto fdFollowConfigQfIdDto){
        if(fdFollowConfigQfIdDto.getId() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        FdFollowConfigQf fdFollowConfigQf = fdFollowConfigQfMapper.selectById(fdFollowConfigQfIdDto.getId(), fdFollowConfigQfIdDto.getMerId());

        if(fdFollowConfigQf == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "此跟发配置不存在");
        }
        //删除
        fdFollowConfigQfMapper.deleteById(fdFollowConfigQfIdDto.getId(), fdFollowConfigQfIdDto.getMerId());

        //查询旧气氛组机器人信息用于删除旧的缓存
        List<FdFollowConfigQfGroupTuo> fdFollowConfigQfGroupTuoList_old = fdFollowConfigQfGroupTuoMapper.findByListByFdFollowConfigQfId(fdFollowConfigQf.getId(), fdFollowConfigQfIdDto.getMerId());

        //新建新的气氛组机器人信息列表
        List<FdFollowConfigQfGroupTuo> fdFollowConfigQfGroupTuoList_new = new ArrayList<>();
        //批量删除该任务的关键词
        fdFollowConfigQfKeywordMapper.deleteByFdFollowConfigQfId(fdFollowConfigQfIdDto.getId(), fdFollowConfigQfIdDto.getMerId());
        //批量删除该任务群信息
        fdFollowConfigQfGroupMapper.deleteByFdFollowConfigQfId(fdFollowConfigQfIdDto.getId(), fdFollowConfigQfIdDto.getMerId());
        //批量删除该任务群托机器人信息
        fdFollowConfigQfGroupTuoMapper.deleteByFdFollowConfigQfId(fdFollowConfigQfIdDto.getId(), fdFollowConfigQfIdDto.getMerId());

        //删除旧的机器人缓存
        if(fdFollowConfigQfGroupTuoList_old != null && fdFollowConfigQfGroupTuoList_old.size() > 0){
            for (FdFollowConfigQfGroupTuo fdFollowConfigQfGroupTuo_old : fdFollowConfigQfGroupTuoList_old) {
                String cacheKey_old = String.format(RedisCacheKeyEnum.FD_FOLLOW_QF_TASK_CACHE_KEY.getKey(), fdFollowConfigQfIdDto.getMerId(), fdFollowConfigQfGroupTuo_old.getTuoDeviceId(), fdFollowConfigQfGroupTuo_old.getGroupWxid(), fdFollowConfigQfGroupTuo_old.getGroupUserWxid());
                //先删除旧的缓存
                redisTemplate.delete(cacheKey_old);
            }
        }
    }


    /**
     * 设置是否开启
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param fdFollowConfigQfStatusDto
     * @return null
     */
    @Transactional
    public void updateStatus(FdFollowConfigQfStatusDto fdFollowConfigQfStatusDto){

        if(fdFollowConfigQfStatusDto.getId() == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        FdFollowConfigQf fdFollowConfigQf = fdFollowConfigQfMapper.selectById(fdFollowConfigQfStatusDto.getId(), fdFollowConfigQfStatusDto.getMerId());

        if(fdFollowConfigQf == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "此跟发配置不存在");
        }

        Long merId = fdFollowConfigQf.getMerId();

        fdFollowConfigQf.setStatus(Tools.getInteger(fdFollowConfigQfStatusDto.getStatus()));

        //修改状态
        int i = fdFollowConfigQfMapper.updateStatusById(fdFollowConfigQf);
        //修改成功
        if(i==1){
            //查询旧气氛组机器人信息用于删除旧的缓存
            List<FdFollowConfigQfGroupTuo> fdFollowConfigQfGroupTuoList_old = fdFollowConfigQfGroupTuoMapper.findByListByFdFollowConfigQfId(fdFollowConfigQf.getId(), fdFollowConfigQf.getMerId());
            if(Tools.getInteger(fdFollowConfigQfStatusDto.getStatus()).intValue() == 0){ //关闭
                //删除旧的机器人缓存
                if(fdFollowConfigQfGroupTuoList_old != null && fdFollowConfigQfGroupTuoList_old.size() > 0){
                    for (FdFollowConfigQfGroupTuo fdFollowConfigQfGroupTuo_old : fdFollowConfigQfGroupTuoList_old) {
                        String cacheKey_old = String.format(RedisCacheKeyEnum.FD_FOLLOW_QF_TASK_CACHE_KEY.getKey(), fdFollowConfigQf.getMerId(), fdFollowConfigQfGroupTuo_old.getTuoDeviceId(), fdFollowConfigQfGroupTuo_old.getGroupWxid(), fdFollowConfigQfGroupTuo_old.getGroupUserWxid());
                        //先删除旧的缓存
                        redisTemplate.delete(cacheKey_old);
                    }
                }
            }else{ //开启
                //新增加气氛组缓存
                if(fdFollowConfigQfGroupTuoList_old != null && fdFollowConfigQfGroupTuoList_old.size() > 0) {

                    //查询旧气氛组机器人信息用于删除旧的缓存
                    List<FdFollowConfigQfKeyword> fdFollowConfigQfKeywordList = fdFollowConfigQfKeywordMapper.findByListByFdFollowConfigQfId(fdFollowConfigQf.getId(), fdFollowConfigQf.getMerId());

                    //先封装关键词列表
                    List<FollowQfConfig.KeyWordInfo> keyWordInfoList = new ArrayList<>();
                    if(fdFollowConfigQfKeywordList != null && fdFollowConfigQfKeywordList.size() > 0){
                        for (FdFollowConfigQfKeyword fdFollowConfigQfKeyword : fdFollowConfigQfKeywordList) {
                            FollowQfConfig.KeyWordInfo keyWordInfo = new FollowQfConfig.KeyWordInfo();
                            keyWordInfo.setKeyword(fdFollowConfigQfKeyword.getKeyword());
                            keyWordInfo.setType(fdFollowConfigQfKeyword.getType());
                            keyWordInfoList.add(keyWordInfo);
                        }
                    }

                    for (FdFollowConfigQfGroupTuo fdFollowConfigQfGroupTuo_new : fdFollowConfigQfGroupTuoList_old) {
                        String cacheKey_new = String.format(RedisCacheKeyEnum.FD_FOLLOW_QF_TASK_CACHE_KEY.getKey(), merId, fdFollowConfigQfGroupTuo_new.getTuoDeviceId(), fdFollowConfigQfGroupTuo_new.getGroupWxid(), fdFollowConfigQfGroupTuo_new.getGroupUserWxid());
                        FollowQfConfig followQfConfig_redis = new FollowQfConfig();
                        followQfConfig_redis.setFdFollowConfigQfId(fdFollowConfigQf.getId());
                        followQfConfig_redis.setKeywords(keyWordInfoList);
                        //添加新的缓存
                        redisTemplate.opsForValue().set(cacheKey_new, JSONObject.toJSONString(followQfConfig_redis));

                    }
                }
            }
        }else{
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "修改失败，网络延迟");
        }
    }

}
